package com.huage_08.lesson_05;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        //创建服务端的ServerSocket
        ServerSocket ss = new ServerSocket(1997);

        //接收数据
        Socket s = ss.accept();
//        InputStream is = s.getInputStream();
//        byte[] bytes = new byte[1024];
//        int len;
//        while ((len=is.read(bytes))!=-1){
//            String data = new String(bytes,0,len);
//            System.out.println("接收的数据是:" + data);
//        }

        BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
        String line;
        while ((line=br.readLine())!=null){
            System.out.println("接收的数据是:" + line);
        }

        //关闭服务端的Socket对象
        s.close();
        ss.close();
    }
}
